﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
    public class individual_clas
    {
        public User u = User.createObj();

        public void Add_individual(string desc,int from,int to,string day,int num,string month,string year)
        {

            SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\elkolyaa\calendar-maintainer-508c42534a4c\calendar-maintainer-508c42534a4c\WindowsFormsApplication1\WindowsFormsApplication1\usersDB.mdf;Integrated Security=True");
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
 
            cn.Open();
            calendar c = new calendar();
            bool check = c.check_conflect(u.from, u.to, u.numday, u.Month, u.yearr);

            if (check)
            {
                cmd.CommandText = "insert into users (event_desc,event_timefrom,event_timeto,event_day,event_numDay,event_month,event_year) values('" + u.descrip + " ', '" + u.from + "' ,' " + u.to + "'  , '" + u.dayy + "', '" + u.num + "' , '" + u.Month + "' , '" + u.yearr + "')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("the event is saved", "database");
            }

            else
                MessageBox.Show("Duplicated data", "Error !! ");


        }

    }
}
